package com.cobra.upload.result;

//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//


import cn.hutool.core.util.StrUtil;

import java.io.Serializable;

public class Result<T> implements Serializable {
    private static final long serialVersionUID = -2683214929256826770L;
    private Integer code;
    private String msg;
    private T data;

    private Result() {
    }

    public Result(Integer code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public static <T> Result<T> success() {
        return new Result(ResultStatus.SUCCESS.getCode(), ResultStatus.SUCCESS.getMsg());
    }

    public static <T> Result<T> success(String msg) {
        return new Result(ResultStatus.SUCCESS.getCode(), msg);
    }

    public static <T> Result<T> success(T data) {
        Result<T> result = success();
        result.data = data;
        return result;
    }

    public static <T> Result<T> success(String msg, T data) {
        Result<T> result = success(msg);
        result.data = data;
        return result;
    }


    public static <T> Result<T> sysError() {
        return new Result(ResultStatus.SYS_ERROR.getCode(), ResultStatus.SYS_ERROR.getMsg());
    }

    public static <T> Result<T> sysError(String msg) {
        return new Result(ResultStatus.SYS_ERROR.getCode(), msg);
    }


    public static <T> Result<T> other(ResultStatus ResultStatus) {
        return new Result(ResultStatus.getCode(), ResultStatus.getMsg());
    }

    public static <T> Result<T> other(ResultStatus ResultStatus, String msg) {
        return new Result(ResultStatus.getCode(), msg);
    }

    public static <T> Result<T> other(ResultStatus ResultStatus, T data) {
        Result<T> result = other(ResultStatus);
        result.data = data;
        return result;
    }

    public static <T> Result<T> other(ResultStatus ResultStatus, String msg, T data) {
        Result<T> result = new Result(ResultStatus.getCode(), msg);
        result.data = data;
        return result;
    }

    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder("Result{");
        if (this.code != null) {
            sb.append("code=").append(this.code);
        }

        if (StrUtil.isNotEmpty(this.msg)) {
            sb.append(", msg='").append(this.msg).append('\'');
        }

        if (this.data != null) {
            sb.append(", data=").append(this.data);
        }

        sb.append("}");
        return sb.toString();
    }

    public Integer getCode() {
        return this.code;
    }

    public String getMsg() {
        return this.msg;
    }

    public T getData() {
        return this.data;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public void setData(T data) {
        this.data = data;
    }


    protected boolean canEqual(Object other) {
        return other instanceof Result;
    }

}
